﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ScrumMonster
{
    public class Task
    {        
        public string Number { get; set; }
        //public string Project { get; set; }
        public string Title  { get; set; }
        public string Status { get; set; }
        //public string PersonAssignedTo { get; set; }
        public string EmailAssignedTo { get; set; }
        public TimeSpan EstimatedTime { get; set; }
        public TimeSpan ElapsedTime { get; set; }
        //public string Resolved { get; set; }

        public XElement XElement
        {
            get
            {
                return new XElement("task",
                                    new XElement("number", this.Number),
                                    new XElement("title", this.Number),
                                    new XElement("status", this.Number),
                                    //new XElement("personassignedto", this.Number),
                                    new XElement("emailassignedto", this.Number),
                                    new XElement("elapsedtime", 
                                                new XElement("days", this.EstimatedTime.Days),
                                                new XElement("hours", this.EstimatedTime.Hours),
                                                new XElement("minutes", this.EstimatedTime.Minutes)
                                        ));
            }
        }

        public Task()
        {
        }

        internal Task(XElement element, Sprint sprint)
        {
            this.Number = element.Elements("number").First().Value;
            //this.Project = element.Elements("project").First().Value;
            this.Title = element.Elements("title").First().Value;
            this.Status = element.Elements("status").First().Value;
            //this.PersonAssignedTo = element.Elements("personassignedto").First().Value;
            this.EmailAssignedTo = element.Elements("emailassignedto").First().Value;
            this.ElapsedTime = new TimeSpan(int.Parse(element.Elements("elapsedtime").First().Value), 0, 0);
            //this.Resolved = element.Elements("resolved").First().Value;                        
        }

    }
}
